/**
 * 注册 js
 */
//验证码
var waits = 30;

function counts(target) {
    if (waits == 0) {
        target.removeAttribute('disabled');
        target.removeAttribute('style');
        target.value = "获取验证码";
        waits = 30;
    } else {
        target.setAttribute('disabled', true);
        target.setAttribute('style', 'background-color: #bbb;');
        target.value = waits + " s";
        waits--;
        setTimeout(function () {
            counts(target);
        }, 1000);
    }
}

function getVerifyCode(obj) {
    var phone = $('input[name="phone"]').val();
    if (isNullOrEmpty(phone)) {
        layer.msg("手机号不能为空");
        return false;
    }
    if (!isTrueMobile(phone)) {
        layer.msg("手机号不正确");
        return false;
    }
    var post_url = toRoute('api/account/getMobileMsg');
    var token = localStorage.wdczy_token;
    $.post(post_url, {'token': token, 'phone': phone}, function (data) {
        if (data.errorCode == '200') {

        } else {
            layer.msg('发送失败，请稍候重试');
        }
    }, 'json');
    counts(obj);
}

function bandPhone() {
    var phone = $('input[name="phone"]').val();
    var code = $('input[name="code"]').val();
    if (isNullOrEmpty(phone)) {
        layer.msg("手机号不能为空");
        return false;
    }
    if (!isTrueMobile(phone)) {
        layer.msg("手机号不正确");
        return false;
    }
    if (isNullOrEmpty(code)) {
        layer.msg("验证码不能为空");
        return false;
    }
    var post_url = toRoute('api/account/bindingPhone');
    var token = localStorage.wdczy_token;
    $.post(post_url, {'token': token, 'phone': phone, 'code': code}, function (data) {
        if (data.errorCode == '200') {
            yzmClose();
            if (isGroupBuy == 0) {
                //下单
                AjaxPlaceOrder();
            } else {
                //团购下单
                AjaxGroupPlaceOrder();
            }
        } else {
            if (data.errorCode == '10006') {
                layer.msg(data.errorMsg);
            } else {
                layer.msg('操作失败，请重试');
            }
        }
    }, 'json');

}

function yzmShow(){
    BGimgshow();
    $(".tk_yz").removeClass("dis_none").addClass("dis_block");
    $("html,body").addClass("noscoll");
}

function yzmClose(){
    if ($('.tk_number').hasClass('dis_none')) {
        closeBGimg();
    }
    $(".tk_yz").removeClass("dis_block").addClass("dis_none");
    $("html,body").removeClass("noscoll");
}
